package br.com.engine;

import java.awt.Point;

import org.jbox2d.common.Vec2;

public class Vector2 
{
	private Point positionPixel;
	private Vec2  positionMeter;
	
	public int   xp;
	public int   yp;
	public float xm;
	public float ym;
	
	public Point getPositionPixel( ) 
	{
		return positionPixel;
	}
	
	public void setPositionPixel( int x, int y ) 
	{
		this.positionPixel.x = x;
		this.positionPixel.y = y;
		
		this.positionMeter.x = toMeter( x );
		this.positionMeter.y = toMeter( y );
		
		updatePositions( );
	}

	private void updatePositions( )
	{
		this.xp = this.positionPixel.x;
		this.yp = this.positionPixel.y;
		this.xm = this.positionMeter.x;
		this.ym = this.positionMeter.y;
	}
	
	public Vec2 getPositionMeter( ) 
	{
		return positionMeter;
	}
	
	public void setPositionMeter( float x, float y ) 
	{
		this.positionMeter.x = x;
		this.positionMeter.y = y;
		
		this.positionPixel.x = toPixel( x );
		this.positionPixel.y = toPixel( y );
		
		updatePositions( );
	}
	
	public Vector2( )
	{
		this.positionMeter = new Vec2( );
		this.positionPixel = new Point( );
		
		updatePositions( );
	}
	
	public Vector2( int x, int y )
	{
		this.positionPixel = new Point( x,            y            );
		this.positionMeter = new Vec2 ( toMeter( x ), toMeter( y ) );
		
		updatePositions( );
	}
	
	/**
	 * coordenada x em metros para coordenada em pixel
	 * @param size
	 * @return
	 */
	public int toPixel( float size )
	{
        int x = (int)( 50.0f * size );
        return x;
    }
 
    /**
	 * coordenada x em pixel para coordenada em metro
     * @param size
     * @return
     */
    public float toMeter( int size )
    {
        float x =  0.02f * size;
        return x;
    }
}